import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/home.vue'
import About from '../views/about.vue'
import AdminEbook from '../views/admin/admin-ebook.vue'
import MainLayout from '@/layout/MainLayout/MainLayout.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'root',
      component: MainLayout,
      children: [
        {
          path: '/home',
          name: 'home',
          component: Home,
          meta: {
            title: '首页',
            icon: 'House',
          },
        },
        {
          path: '/AdminEbook',
          name: 'AdminEbook',
          component: AdminEbook,
          meta: {
            title: '电子书管理',
            icon: 'Memo',
          },
        },
        {
          path: '/about',
          name: 'about',
          component: About,
          meta: {
            title: '关于我们',
            icon: 'UserFilled',
          },
        },
      ],
    },
  ],
})

// 全局路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next('/home')
  } else {
    next()
  }
})

export default router
